﻿using UnityEngine;
using UnityEngine.UI;

public class MapShop : ShopItem {

//	public int index;
//	public Image img;

	public override void CheckStatus ()
	{
		base.CheckStatus ();
		PlayerPrefs.SetInt ("map0", 1);
		if (PlayerPrefs.GetInt ("map" + index.ToString ()) == 1) {
			img.color = Color.white;
			costGroup.SetActive (false);
		} else {
			img.color = new Color32 (255,255,255, 155);
		}
		selectedImg.gameObject.SetActive (GameManager.CurrMap == index);
		if (GameManager.CurrMap == index)
			UiManager.tempMapSelect = selectedImg.gameObject;
	}

	public override void OnClickButton ()
	{
		base.OnClickButton ();
			if (UiManager.tempMapSelect != null && mapLockStage == 1)
				UiManager.tempMapSelect.SetActive (false);
		if (mapLockStage == 0) {
			if (GameStatistic.Coin > price) {
				mapLockStage = 1;
				UiManager.SetCoinText (true, -price);
			}
			else  {
				print ("NOT ENOUGH COIN");
			}
		} else {

			GameManager.CurrMap = index;
			BattleGroundHelper.SetBackground ();
		}
		CheckStatus ();
		AudioManager.PlayOneShoot (5);
	}
}
